﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ins = LEET.StandardModuals.Instructions;
using LEET.CommonInterfaces.TestControls;
using Compiled_Tests;
using System.Windows.Automation;
using LEET.LEETCommon.WidgetLookup;

namespace LEET.StandardModuals.Instructions.Actions
{
    public class Invoke : Ins.Action
    {
        public Invoke(String[] args)
            : base(args)
        {

        }

        public static IAutomationActionResult StaticCall(IBox box, String element)
        {
            AutomationElement e = WidgetFinder.Find(element, box.RootElement);
            Object obj;
            e.TryGetCurrentPattern(InvokePattern.Pattern, out obj);
            InvokePattern pattern = obj as InvokePattern;
            if (pattern != null)
                pattern.Invoke();
            return new AutomationActionResult();
        }

        public override String RenderStaticCall()
        {
            return "LEET.StandardModuals.Instructions.Actions.Invoke.StaticCall(Box, \"" + element + "\")";
        }

        public override string PlainText()
        {
            String [] split = this.element.Split(',');
            return "Clicked on " + split[split.Length - 1] + ".";
        }
    }
}
